#include "QtPrivateDeclar.h"

#include <CommandUtil/CommandUtil.h>

QtPrivateDeclar::QtPrivateDeclar(): d_ptr(new QtPrivateDeclarPrivate(this))
{
    
}

void QtPrivateDeclar::setModule(QString module) {
    // module
    QString content = CommandUtil::RunCommand("modinfo", QStringList(module));
    // for (auto &line : content.split("\n", QString::SkipEmptyParts))
    for (auto &line : content.split("\n"))
    {
        if (line.startsWith("filename")) {
            setFilename(line.split(":")[1].trimmed());
        }
        if (line.startsWith("firmware")) {
            // setFirmware(line.split(":")[1].trimmed());
        }
        if (line.startsWith("license")) {
            setLicense(line.split(":")[1].trimmed());
        }
        if (line.startsWith("softdep")) {
            setSoftdep(line.split(":")[1].trimmed());
        }
        if (line.startsWith("description")) {
            setDescription(line.split(":")[1].trimmed());
        }
        if (line.startsWith("author")) {
            setAuthor(line.split(":")[1].trimmed());
        }
        if (line.startsWith("srcversion")) {
            setSrcversion(line.split(":")[1].trimmed());
        }
        if (line.startsWith("retpoline")) {
            setRetpoline(line.split(":")[1].trimmed());
        }
        if (line.startsWith("depends")) {
            setDepends(line.split(":")[1].trimmed());
        }
        if (line.startsWith("intree")) {
            setIntree(line.split(":")[1].trimmed());
        }
        if (line.startsWith("vermagic")) {
            setVermagic(line.split(":")[1].trimmed());
        }
        if (line.startsWith("sig_id")) {
            setSig_id(line.split(":")[1].trimmed());
        }
        if (line.startsWith("signer")) {
            setSigner(line.split(":")[1].trimmed());
        }
        if (line.startsWith("sig_key")) {
            setSig_key(line.right(line.length() - 8).trimmed());
        }
        if (line.startsWith("sig_hashalgo")) {
            setSig_hashalgo(line.split(":")[1].trimmed());
        }
        if (line.startsWith("signature")) {
            setSignature(line.split(":")[1].trimmed());
        }
        if (line.startsWith("alias")) {
            setAlias(getAlias() << line.right(line.length() - 6).trimmed());
        }
        if (line.startsWith("parm")) {
            setParm(getParm() << line.right(line.length() - 5).trimmed());
        }
    }
    
}


void QtPrivateDeclar::setFilename(QString filename) {
    Q_D(QtPrivateDeclar);
    d->filename = filename;
}
QString QtPrivateDeclar::getFilename() {
    Q_D(QtPrivateDeclar);
    return d->filename;
}

void QtPrivateDeclar::setFirmware(QStringList firmware) {
    Q_D(QtPrivateDeclar);
    d->firmware = firmware;
}
QStringList QtPrivateDeclar::getFirmware() {
    Q_D(QtPrivateDeclar);
    return d->firmware;
}

void QtPrivateDeclar::setLicense(QString license) {
    Q_D(QtPrivateDeclar);
    d->license = license;
}
QString QtPrivateDeclar::getLicense() {
    Q_D(QtPrivateDeclar);
    return d->license;
}

void QtPrivateDeclar::setSoftdep(QString softdep) {
    Q_D(QtPrivateDeclar);
    d->softdep = softdep;
}
QString QtPrivateDeclar::getSoftdep() {
    Q_D(QtPrivateDeclar);
    return d->softdep;
}

void QtPrivateDeclar::setDescription(QString description) {
    Q_D(QtPrivateDeclar);
    d->description = description;
}
QString QtPrivateDeclar::getDescription() {
    Q_D(QtPrivateDeclar);
    return d->description;
}

void QtPrivateDeclar::setAuthor(QString author) {
    Q_D(QtPrivateDeclar);
    d->author = author;
}
QString QtPrivateDeclar::getAuthor() {
    Q_D(QtPrivateDeclar);
    return d->author;
}

void QtPrivateDeclar::setSrcversion(QString srcversion) {
    Q_D(QtPrivateDeclar);
    d->srcversion = srcversion;
}
QString QtPrivateDeclar::getSrcversion() {
    Q_D(QtPrivateDeclar);
    return d->srcversion;
}

void QtPrivateDeclar::setRetpoline(QString retpoline) {
    Q_D(QtPrivateDeclar);
    d->retpoline = retpoline;
}
QString QtPrivateDeclar::getRetpoline() {
    Q_D(QtPrivateDeclar);
    return d->retpoline;
}

void QtPrivateDeclar::setDepends(QString depends) {
    Q_D(QtPrivateDeclar);
    d->depends = depends;
}
QString QtPrivateDeclar::getDepends() {
    Q_D(QtPrivateDeclar);
    return d->depends;
}

void QtPrivateDeclar::setIntree(QString intree) {
    Q_D(QtPrivateDeclar);
    d->intree = intree;
}
QString QtPrivateDeclar::getIntree() {
    Q_D(QtPrivateDeclar);
    return d->intree;
}

void QtPrivateDeclar::setVermagic(QString vermagic) {
    Q_D(QtPrivateDeclar);
    d->vermagic = vermagic;
}
QString QtPrivateDeclar::getVermagic() {
    Q_D(QtPrivateDeclar);
    return d->vermagic;
}

void QtPrivateDeclar::setSig_id(QString sig_id) {
    Q_D(QtPrivateDeclar);
    d->sig_id = sig_id;
}
QString QtPrivateDeclar::getSig_id() {
    Q_D(QtPrivateDeclar);
    return d->sig_id;
}

void QtPrivateDeclar::setSigner(QString signer) {
    Q_D(QtPrivateDeclar);
    d->signer = signer;
}
QString QtPrivateDeclar::getSigner() {
    Q_D(QtPrivateDeclar);
    return d->signer;
}

void QtPrivateDeclar::setSig_key(QString sig_key) {
    Q_D(QtPrivateDeclar);
    d->sig_key = sig_key;
}
QString QtPrivateDeclar::getSig_key() {
    Q_D(QtPrivateDeclar);
    return d->sig_key;
}

void QtPrivateDeclar::setSig_hashalgo(QString sig_hashalgo) {
    Q_D(QtPrivateDeclar);
    d->sig_hashalgo = sig_hashalgo;
}
QString QtPrivateDeclar::getSig_hashalgo() {
    Q_D(QtPrivateDeclar);
    return d->sig_hashalgo;
}

void QtPrivateDeclar::setSignature(QString signature) {
    Q_D(QtPrivateDeclar);
    d->signature = signature;
}
QString QtPrivateDeclar::getSignature() {
    Q_D(QtPrivateDeclar);
    return d->signature;
}

void QtPrivateDeclar::setAlias(QStringList alias) {
    Q_D(QtPrivateDeclar);
    d->alias = alias;
}
QStringList QtPrivateDeclar::getAlias() {
    Q_D(QtPrivateDeclar);
    return d->alias;
}

void QtPrivateDeclar::setParm(QStringList parm) {
    Q_D(QtPrivateDeclar);
    d->parm = parm;
}
QStringList QtPrivateDeclar::getParm() {
    Q_D(QtPrivateDeclar);
    return d->parm;
}
